import axios from 'axios'
import {getToken} from './session.js'
import { ElMessage } from 'element-plus'

const service = axios.create({
    baseURL: 'http://192.168.5.60:8765/api/front',
    timeout: 1000,
})
//请求拦截器
service.interceptors.request.use((config) => {
    config.headers['token'] = getToken();
    return config;
}, (error) => {
    return Promise.reject(error);
})

//响应拦截器
service.interceptors.response.use((response) => {
    let {status, message} = response.data;
    if(status !== 200){
        ElMessage({message: message || 'error', type: 'warning', duration: 5 * 1000})
    }
    return response;
}, (error) => {
    return Promise.reject(error);
})
export default service
